import java.util.Stack;

public class Test {
    //括号匹配
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                char ch2 = stack.pop();
                if (!istrue(ch2, ch)) {
                    return false;
                }
            }
        }
        if (!stack.isEmpty()) {
            return false;
        }
        return true;
    }

    public boolean istrue(char ch2, char ch) {
        switch (ch2) {
            case '(':
                return ch == ')';
            case '[':
                return ch == ']';
            case '{':
                return ch == '}';

        }
        return false;
    }

    //逆波兰表达式（后缀表达式）求值
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String str : tokens){
            if(!isOperator(str)){
                int x = Integer.parseInt(str);
                stack.push(x);
            } else {
                int b = stack.pop();
                int a = stack.pop();
                int x = ret(a,b,str);
                stack.push(x);
            }
        }
        return stack.pop();
    }
    private boolean isOperator(String ch){
        if(ch.equals("+") || ch.equals("-") || ch.equals("*") || ch.equals("/")){
            return true;
        }
        return false;
    }
    private int ret(Integer a, Integer b, String str) {
        switch (str) {
            case "+":
                return a + b;
            case "-":
                return a - b;
            case "*":
                return a * b;
            case "/":
                return a / b;
            default:
                return -1;
        }
    }

    //出入栈次序匹配
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0; i < pushV.length; i++){
            stack.push(pushV[i]);
            while(!stack.empty() && j < popV.length
                    && stack.peek().equals(popV[j])){
                stack.pop();
                j++;
                continue;
            }
        }
        return stack.empty();
    }
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(512);
        minStack.push(-1024);
        minStack.push(512);
        minStack.push(-1024);
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
    }

}